<?php

class Model_PersistentLogin extends Joob_Db_Table	{
	
	protected $key = "id";
	
	protected $db = "persistent_login";
	
	public static function createExpiredCookies()	{
		setcookie('persistent_userID', -1, time()-3600);
		setcookie('persistent_loginID', -1, time()-3600);
	}
	
	public function generateCookie($userID)	{
		$this->loginID = sha1("h&%%*((^%hukj".time().$userID.rand());
		$this->userID = $userID;
		$this->since = time();
		return $this->insert('userID, loginID, since');
	}
	
	public function isCookieValid()	{
		$result = $this->exist('userID, loginID');
		if (!$result)
			return false;
		//FIXME: Check for expired date?
		return true;
	}
}

?>